package com.colin.springbootsource.controller;

import com.colin.springbootsource.domain.TbEmployee;
import com.colin.springbootsource.service.DemoService;
import com.colin.springbootsource.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @author: Colin
 * 2019/12/21 15:11
 * @desc todo
 * @email zhaod@oceansoft.com.cn
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private DemoService demoService;

    @Resource
    private TestService testService;

    @GetMapping("{id}")
    public String findEmployee(@PathVariable("id") int id){
       return Optional.ofNullable(demoService.getTbEmployeeById(id)).map(TbEmployee::toString).orElse("未查到员工数据");
    }

    @RequestMapping("test")
    public String testInitializer(){
        return testService.test();
    }
}
